﻿using System.Security.Principal;

namespace Sidvall.Security
{
    /// <summary>
    /// Read access: Authenticated users
    /// Write access: Authenticated users
    /// </summary>
    public class IdentityAuthorizationProvider : PublicAuthorizationProvider
    {
        #region Public Members

        #region ToString

        public override string ToString()
        {
            return "AuthorizationProvider - Identity";
        }

        #endregion

        // Protected
        #region DefaultResourceItemAccessLevel

        protected override ResourceItemAccessLevel DefaultResourceItemAccessLevel
        {
            get
            {
                return ResourceItemAccessLevel.Protected;
            }
        }

        #endregion
        #region DefaultResourceItemDescription

        protected override string DefaultResourceItemDescription
        {
            get
            {
                return "Authenticated";
            }
        }

        #endregion

        #region AuthorizeProtected

        protected override bool AuthorizeProtected(IPrincipal principal)
        {
            return principal?.Identity?.IsAuthenticated == true;
        }

        #endregion

        #endregion
        #region Constructors

        public IdentityAuthorizationProvider()
        {
        }

        #endregion
    }
}
